<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Template Library &#8250; Layouts</title>

<style type='text/css' media='all'>@import url('./userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
<script type="text/javascript" src="js/nav.js"></script>

<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />

</head>
<body>

<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('null');</script></div></div>
<div id="nav2"><a name="top">&nbsp;</a><a href="#" id="toggle_toc"><img src="images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>Documentation</h1></td>
<td id="breadcrumb_right">Author:<a href="http://philsturgeon.co.uk/">Phil Sturgeon</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->


<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://philsturgeon.co.uk/code/codeigniter-template">Template</a> &nbsp;&#8250;&nbsp;
<a href="index.html">Documentation</a> &nbsp;&#8250;&nbsp;
Partials
</td>
</tr>
</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">
	<h1>Template</h1>

	<h2>Partials</h2>

	<p>
		When you start creating multiple <a href="layouts.html">Layouts</a> you will soon start to realize that while they are not all the same they will share lots of stuff. Often the
		header will be different but there could be two columns instead of one, etc.
	</p>

	<p>
		Partials can go anywhere in your views folder (or themes and modules view folder) like <dfn>application/views/header.php</dfn>.
	</p>

	<p>
		To attach a Partial (from a view file) to a Layout you will need to use the <kbd><a href="library.html#set_partial">set_partial()</a></kbd> method.
		Give the partial name, then enter it's path and optionally give it some special data that will only exist for that partial.
	</p>

	<p>
		You can also inject strings into the template as partials using the <kbd><a href="library.html#inject_partial">inject_partial()</a></kbd> method.
		This method is almost identical to <kbd><a href="library.html#set_partial">set_partial()</a></kbd> but the second argument is a HTML string and not a view file.
	</p>

	<h3>Example (PHP)</h3>

	<p>The easiest layout in the world is this:</p>

	<pre>&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;?php echo $template['partials']['header']; ?&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;h1&gt;&lt;?php echo $template['title']; ?&gt;&lt;/h1&gt;
		&lt;?php echo $template['body']; ?&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>

	<h3>Example (Parser)</h3>

	<p>Using the parser syntax you can do this instead:</p>

	<pre>&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
		{$template.partials.header}
	&lt;/head&gt;
	&lt;body&gt;
		&lt;h1&gt;{$template.title}&lt;/h1&gt;
		{$template.body}
	&lt;/body&gt;

&lt;/html&gt;</pre>

	<p class="important"><strong>NOTE:</strong> You can only use the Parser if you have also installed a Parser extensions like <a href="http://philsturgeon.co.uk/code/codeigniter-dwoo" target="_blank">codeigniter-dwoo</a>. This is because CI_Parser does not play nicely with arrays.</p>


</div>
<!-- END CONTENT -->


<div id="footer">
	<p><a href="#top">Top of Page</a></p>
	<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2010 Phil Sturgeon &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
</div>

</body>
</html>